package com.yuanfeng.service.impl;

import com.yuanfeng.basedata.entiry.KcsjMessage;
import com.yuanfeng.basedata.entiry.KcsjUser;
import com.yuanfeng.basedata.repository.KcsjMessageRepository;
import com.yuanfeng.basedata.repository.UserRepository;
import com.yuanfeng.service.MessageManageService;
import com.yuanfeng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @ClassName UserServiceImpl
 * @Description T0D0
 * @Author yuanfeng
 * @Date 2019/9/6 21:50
 * @Version 1.0
 **/
@Service
@Transactional
public class MessageManageServiceImpl implements MessageManageService {

    @Autowired
    private KcsjMessageRepository kcsjMessageRepository;

    /**
     * @Description: 返回存储的留言对象
     * @Param 留言对象
     * @return
     * @date: 2019/9/9 23:25
     */

    @Override
    public KcsjMessage leaveMessage(KcsjMessage kcsjMessage) {

        return kcsjMessageRepository.save(kcsjMessage);
    }

    /**
     * @Description: 根据用户ID得到所有留言
     * @Param 用户ID
     * @return
     * @date: 2019/9/9 23:24
     */

    @Override
    public List<KcsjMessage> listAllMessage(Integer userId) {
        return kcsjMessageRepository.findAllByMessageUserId(userId);
    }

    /**
     * @Description: 列出所有留言
     * @Param
     * @return
     * @date: 2019/9/9 23:50
     */
    @Override
    public List<KcsjMessage> listAllMessages() {
        return kcsjMessageRepository.findAll();
    }

    @Override
    public void deleteByMessageId(Integer messageId) {
        kcsjMessageRepository.deleteById(messageId);
    }

}
